<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>Hello MUI</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">

		<link rel="stylesheet" href="css/mui.min.css">
		<link rel="stylesheet" type="text/css" href="css/feedback.css" />
		<link rel="stylesheet" type="text/css" href="css/iconfont3.css">
		<link rel="stylesheet" type="text/css" href="css/iconfont4.css">
		<link rel="stylesheet" type="text/css" href="css/mui.picker.min.css" />
		<link href="css/mui.poppicker.css" rel="stylesheet" />
		
		<style>
			/* 主界面css*/
			html,
			body {
				background-color: #efeff4;
			}
			.mui-views,
			.mui-view,
			.mui-pages,
			.mui-page,
			.mui-page-content {
				position: absolute;
				left: 0;
				right: 0;
				top: 0;
				bottom: 0;
				width: 100%;
				height: 100%;
				background-color: #efeff4;
			}
			.mui-pages {
				top: 46px;
				height: auto;
			}
			.mui-scroll-wrapper,
			.mui-scroll {
				background-color: #efeff4;
			}
			.mui-page.mui-transitioning {
				-webkit-transition: -webkit-transform 300ms ease;
				transition: transform 300ms ease;
			}
			.mui-page-left {
				-webkit-transform: translate3d(0, 0, 0);
				transform: translate3d(0, 0, 0);
			}
			.mui-ios .mui-page-left {
				-webkit-transform: translate3d(-20%, 0, 0);
				transform: translate3d(-20%, 0, 0);
			}
			.mui-navbar {
				position: fixed;
				right: 0;
				left: 0;
				z-index: 10;
				height: 44px;
				background-color: #f7f7f8;
			}
			.mui-navbar .mui-bar {
				position: absolute;
				background: transparent;
				text-align: center;
			}
			.mui-android .mui-navbar-inner.mui-navbar-left {
				opacity: 0;
			}
			.mui-ios .mui-navbar-left .mui-left,
			.mui-ios .mui-navbar-left .mui-center,
			.mui-ios .mui-navbar-left .mui-right {
				opacity: 0;
			}
			.mui-navbar .mui-btn-nav {
				-webkit-transition: none;
				transition: none;
				-webkit-transition-duration: .0s;
				transition-duration: .0s;
			}
			.mui-navbar .mui-bar .mui-title {
				display: inline-block;
				width: auto;
			}
			.mui-page-shadow {
				position: absolute;
				right: 100%;
				top: 0;
				width: 16px;
				height: 100%;
				z-index: -1;
				content: '';
			}
			.mui-page-shadow {
				background: -webkit-linear-gradient(left, rgba(0, 0, 0, 0) 0, rgba(0, 0, 0, 0) 10%, rgba(0, 0, 0, .01) 50%, rgba(0, 0, 0, .2) 100%);
				background: linear-gradient(to right, rgba(0, 0, 0, 0) 0, rgba(0, 0, 0, 0) 10%, rgba(0, 0, 0, .01) 50%, rgba(0, 0, 0, .2) 100%);
			}
			.mui-navbar-inner.mui-transitioning,
			.mui-navbar-inner .mui-transitioning {
				-webkit-transition: opacity 300ms ease, -webkit-transform 300ms ease;
				transition: opacity 300ms ease, transform 300ms ease;
			}
			.mui-page {
				display: none;
			}
			.mui-pages .mui-page {
				display: block;
			}
			.mui-page .mui-table-view:first-child {
				margin-top: 15px;
			}
			.mui-page .mui-table-view:last-child {
				margin-bottom: 30px;
			}
			.mui-table-view {
				margin-top: 20px;
			}
			
			.mui-table-view span.mui-pull-right {
				color: #999;
			}
			.mui-table-view-divider {
				background-color: #efeff4;
				font-size: 14px;
			}
			.mui-table-view-divider:before,
			.mui-table-view-divider:after {
				height: 0;
			}
			.head {
				height: 40px;
			}
			#head {
				line-height: 40px;
			}
			.head-img {
				width: 40px;
				height: 40px;
			}
			#head-img1 {
				position: absolute;
				bottom: 10px;
				right: 40px;
				width: 40px;
				height: 40px;
			}
			.update {
				font-style: normal;
				color: #999999;
				margin-right: -25px;
				font-size: 15px
			}
			.mui-fullscreen {
				position: fixed;
				z-index: 20;
				background-color: #000;
			}
			.mui-ios .mui-navbar .mui-bar .mui-title {
				position: static;
			}
			/*问题反馈在setting页面单独的css*/
			#feedback .mui-popover{
				position: fixed;
			}
			#feedback .mui-table-view:last-child {
			    margin-bottom: 0px;
			}
			#feedback .mui-table-view:first-child {
			    margin-top: 0px;
			}
			
			/*企业好友css*/
			
			 .oa-contact-cell.mui-table .mui-table-cell {
				padding: 11px 0;
				vertical-align: middle;
			}
			
			.oa-contact-cell {
				position: relative;
				margin: -11px 0;
			}
	
			.oa-contact-avatar {
				width: 75px;
			}
			.oa-contact-avatar img {
				border-radius: 50%;
			}
			.oa-contact-content {
				width: 100%;
			}
			.oa-contact-name {
				margin-right: 20px;
			}
			.oa-contact-name, oa-contact-position {
				float: left;
			}
			/*选择时间和地址的位置*/
				.ui-alert {
			
				padding: 9px 30px;
				font-size: 16px;
			}
			
		</style>
		<link rel="stylesheet" type="text/css" href="css/feedback.css" />
		<link rel="stylesheet" type="text/css" href="css/iconfont.css">
		<link rel="stylesheet" type="text/css" href="css/iconfont2.css">
	</head>

	<body class="mui-fullscreen" onload="getCompanyList();checkJob()">
		<!--页面主结构开始-->
		<div id="app" class="mui-views">
			<div class="mui-view">
				<div class="mui-navbar">
				</div>
				<div class="mui-pages">
				</div>
			</div>
		</div>
		<!--页面主结构结束-->
		<!--单页面开始-->
		<div id="setting" class="mui-page">
			<div class="mui-navbar-inner mui-bar mui-bar-nav">
				<button type="button" class="mui-left mui-btn  mui-btn-link mui-btn-nav mui-pull-left" onclick="javascript:window.location.href='qiye-detail.html' ">
					<span class="mui-icon mui-icon-left-nav"></span>
				</button>
				<h1 class="mui-title">企业信息</h1>
				<button type="button" class="mui-right mui-action-back mui-btn  mui-btn-link mui-btn-nav mui-pull-right">
					<a href="#chanageQiyePart" class="mui-btn-primary">修改</a>
				</button>
			</div>
			
			<div class="mui-page-content" >
				<div class="mui-scroll-wrapper">
					<div class="mui-scroll"> 
				   		<div id="companyMesage" class="mui-content-padded" style="margin: 0px; ">
				   			<!--
                               	作者：1415047267@qq.com
                               	时间：2017-11-20
                               	描述：企业信息
                               -->
				
						</div>	
					</div>
				</div>
			</div>
		</div>
		<!--单页面结束-->
		
		<script>
			var id=localStorage.getItem("employeeid");
			var eJob="";
			function checkJob(){
				var network = true;
				if(mui.os.plus) {
					mui.plusReady(function() {
						if(plus.networkinfo.getCurrentType() == plus.networkinfo.CONNECTION_NONE) {
							network = false;
						}
					});
				}
				if(network) {
						console.log('网络正常,正在发送请求...');
							 mui.ajax({
                                    url:"http://113.71.26.27:8080/tpl/phone/findEmp",
                                    async:true,
     								type:'post',
     								dataType:"json", 
     								data:{
     									id:id
     								},
     							 	success:function(data){
     							 		eJob=data.job;
     							 		
     								}
     						});
					} else {
						mui.toast("当前网络不给力，请稍后再试...");
				}

			}
			
			function getCompanyList(){
				var network = true;
				if(mui.os.plus) {
					mui.plusReady(function() {
						if(plus.networkinfo.getCurrentType() == plus.networkinfo.CONNECTION_NONE) {
							network = false;
						}
					});
				}
				if(network) {
						console.log('网络正常,正在发送请求...');
							 mui.ajax({
                                    url:'http://113.71.26.27:8080/tpl/phone/getAllCompany',
                                    async:true,
     								type:'post',
     								data:{
     									id:id
     								},
     							 	success:function(data){
     							 		var message='';
       									for(var i=0;i<data.length;i++){
       									 var mystime = new Date(data[i].time).toLocaleDateString();
				   								message+="<form class='mui-input-group'>"+
       													"<input type='hidden' name='id' class='mui-input-clear' placeholder='"+data[i].id+"/>"+
														"<div class='logo' >"+
															"<center><img src='http://113.71.26.27:8080/tpl/public/uploadImage/companyLogo/"+data[i].photo+"' style='width:120px; height:120px'/></center>"+
														"</div>"+
														"<div class='mui-input-row'>"+
															"<label>企业名称</label>"+
															"<input type='text' name='name' class='mui-input-clear' placeholder='"+data[i].name+"' readonly='readonly'>"+
														"</div>"+
														"<div class='mui-input-row '>"+
															"<label >注册时间</label>"+
															"<input type='text' name='time' class='mui-input-clear' name='Time' placeholder='"+mystime+"' readonly='readonly'>"+
														"</div>"+
														"<div class='mui-input-row'>"+
															"<label>法定代表人</label>"+
															"<input type='text' name='corporation' class='mui-input-clear' placeholder='"+data[i].corporation+"' readonly='readonly'>"+
														"</div>"+
														"<div class='mui-input-row'>"+
															"<label>企业二维码</label>"+
															"<button type='button' class='mui-right mui-btn-link mui-btn-nav mui-pull-right'>"+
															"<a href='code.html' class='mui-btn-primary'>获取</a>"+
															"</button>"+
														"</div>"+
														"<div class='mui-input-row'>"+
															"<label>地址</label>"+
															"<input type='text' name='address' class='mui-input-clear' placeholder='"+data[i].address+"' readonly='readonly'>"+
														"</div>"+
														"<div class='mui-input-row'>"+
															"<label>客服电话</label>"+
															"<input type='text' name='tel' class='mui-input-clear' placeholder='"+data[i].tel+"' readonly='readonly'>"+
														"</div>"+
														"<div class='mui-input-row' style='height:160px'>"+
															"<label>描述</label>"+
													 		"<textarea id='textarea' rows='5' name='describer' placeholder='"+data[i].describer+"' readonly='readonly'/>"+
														"</div>"+
													"</form>"
													
											
											    $("#cid").val(data[i].id);
												$("#cname").val(data[i].name);	
												$("#ctime").val(mystime);
												$("#ccorporation").val(data[i].corporation);
												$("#ctel").val(data[i].tel);
												$("#cdescriber").val(data[i].describer);
												$("#caddress").val(data[i].address);
												$("#logoImg").attr('src',"http://113.71.26.27:8080/tpl/public/uploadImage/companyLogo/"+data[i].photo);
       										}
       									
       									//$('#ulId').append(com);
       									$('#companyMesage').append(message);
     								}
     							})
					} else {
						mui.toast("当前网络不给力，请稍后再试...");
				}
			}
			var imgData="";
			
			
			function updateqiye(){
				var network = true;
				if(mui.os.plus) {
					mui.plusReady(function() {
						if(plus.networkinfo.getCurrentType() == plus.networkinfo.CONNECTION_NONE) {
							network = false;
						}
					});
				}
				if(network) {
						console.log('网络正常,正在发送请求...');
						if(eJob!="普通员工"){
							 mui.ajax({
                                    url:"http://113.71.26.27:8080/tpl/phone/UpdateCompany",
                                    async:true,
     								type:'post',
     								dataType:"json", 
     								data:{
   									    id:$("#cid").val(),
   									    photo:imgData,
	  									address:$("#caddress").val(),
   									    tel:$("#ctel").val(),
     									describer:$("#cdescriber").val()
     								},
     							 	success:function(data){
     							 		window.location.href="scQiyeMessage.html";
     								}
     						});
     					}else{
     						mui.toast("权限不足！");
     					}
						
					} else {
						mui.toast("当前网络不给力，请稍后再试...");
				}

			}
			
			
			//本地相册选择 
			function galleryImg() {
				plus.gallery.pick(function(a) {
					plus.io.resolveLocalFileSystemURL(a, function(entry) {
						plus.io.resolveLocalFileSystemURL("_doc/", function(root) {
							root.getFile("head.png", {}, function(file) {
								//文件已存在 
								file.remove(function() {
									console.log("file remove success");
									entry.copyTo(root, 'head.png', function(e) {
											var e = e.fullPath + "?version=" + new Date().getTime();
											document.getElementById("logoImg").src = e;
											var image = new Image();
											image.src = e;
											image.onload = function() {
												imgData = getBase64Image(image);
												console.log(imgData);
											}
										},
										function(e) {
											console.log('copy image fail:' + e.message);
										});
								}, function() {
									console.log("delete image fail:" + e.message);
								});
							}, function() {
								//文件不存在 
								entry.copyTo(root, 'head.png', function(e) {
										var path = e.fullPath + "?version=" + new Date().getTime();
										document.getElementById("logoImg").src = path;
										var image = new Image();
										image.src = path;
										image.onload = function() {
											imgData2 = getBase64Image(image);

										}
									},
									function(e) {
										console.log('copy image fail:' + e.message);
									});
							});
						}, function(e) {
							console.log("get _www folder fail");
						})
					}, function(e) {
						console.log("读取拍照文件错误：" + e.message);
					});
				}, function(a) {}, {
					filter: "image"
				})
			};

			//将图片压缩转成base64 
			function getBase64Image(img) {
				var canvas = document.createElement("canvas");
				var width = img.width;
				var height = img.height;
				// calculate the width and height, constraining the proportions 
				if(width > height) {
					if(width > 200) {
						height = Math.round(height *= 200 / width);
						width = 200;
					}
				} else {
					if(height > 200) {
						width = Math.round(width *= 200 / height);
						height = 200;
					}
				}
				canvas.width = width; /*设置新的图片的宽度*/
				canvas.height = height; /*设置新的图片的长度*/
				var ctx = canvas.getContext("2d");
				ctx.drawImage(img, 0, 0, width, height); /*绘图*/
				var dataURL = canvas.toDataURL("image/png", 0.8);
				return dataURL.replace("data:image/png;base64,", "");
			
			}			
		
			
		</script>
		
		<!--      修改企业           -->
		<div id="chanageQiyePart" class="mui-page">
			<div class="mui-navbar-inner mui-bar mui-bar-nav">
				<button type="button" class="mui-left mui-action-back mui-btn  mui-btn-link mui-btn-nav mui-pull-left">
					<span class="mui-icon mui-icon-left-nav"></span>
				</button>
				<h1 class="mui-title">修改企业信息</h1>
			
			<button onclick="updateqiye()" class="mui-right mui-btn  mui-btn-link mui-btn-nav mui-pull-right">
					<a class="mui-btn-primary">提交</a>
				</button>
			</div>
			<div class="mui-page-content">
				<div class="mui-scroll-wrapper">
					<div class="mui-scroll">
						<div id="changCompany" class="mui-content-padded" style="margin: 0px; ">
				
				<form id="UpdateCompany" class="mui-input-group">
					<input id="cid" type="hidden" name="id">
					<div class="logo">
						<input id="cphoto" type="hidden" name="photo">
						<center><a id='logo' onclick='galleryImg()'><img id='logoImg' style='width:120px; height:120px'/></a></center>
					</div>
					
					<div class="mui-input-row">
						<label>企业名称</label>
						 <input id="cname" type="text" name="name"  readonly="readonly">
					</div>
					<div class="mui-input-row ">
						<label >注册时间</label>
						<input id="ctime" type="text" name="time" readonly="readonly">
					</div>
					
					
					<div class="mui-input-row">
						<label>法定代表人</label>
						<input id="ccorporation" type="text" name="corporation"  readonly="readonly" >
					</div>
					<div class="mui-input-row">
						<label>地址</label>					
						<input id='caddress' type="text" name="address" class="mui-input-clear" />
					</div>
					
					<div class="mui-input-row">
						<label>客服电话</label>
						<input id="ctel" type="text" name="tel" class="mui-input-clear">
					</div>
					<div class="mui-input-row" style="height: 160px;">
						<label>描述</label>
						<textarea id="cdescriber" rows="5" name="describer" >
					  </textarea>	
					</div>
				</form>
					
						</div>	
					</div>
				</div>
			</div>
		</div>

	</body>
	<script src="js/mui.min.js "></script>
	<script src="js/mui.view.js "></script>
	<script src='js/feedback.js'></script>
	<script src="js/mui.picker.min.js"></script>
	<script src="js/mui.poppicker.js"></script>
	<script src="js/city.data.js" type="text/javascript" charset="utf-8"></script>
	<script src="js/city.data-3.js" type="text/javascript" charset="utf-8"></script>
	<script type="text/javascript" src="jquery.js"></script> 
	<script type="text/javascript" src="jquery.qrcode.min.js"></script> 
		
	<script type="text/javascript" src="js/jquery-3.2.1.min.js"></script>
	<script>
		
		
		mui.init({
  			gestureConfig:{
    		longtap: true, //默认为false
    		release:true
   			}
		});
		//mui.init();
		//初始化单页view
		var viewApi = mui('#app').view({
			defaultPage: '#setting'
		});
		//初始化单页的区域滚动
		mui('.mui-scroll-wrapper').scroll();
		//分享操作

		var view = viewApi.view;
		(function($) {
			//处理view的后退与webview后退
			var oldBack = $.back;
			$.back = function() {
				if (viewApi.canBack()) { //如果view可以后退，则执行view的后退
					viewApi.back();
				} else { //执行webview后退
					window.location.href = "qiye-detail.html";
				}
			};
			
		})(mui);
	
			
			
		
	</script>
	
</html>